package com.example.lishop.controller

import com.example.lishop.base.MyResponse
import com.example.lishop.entity.BCompanyEntity
import com.example.lishop.entity.bean.BaseListBean
import com.example.lishop.service.LiValid
import com.example.lishop.service.impl.CompanyServiceImpl
import com.example.lishop.util.SnowflakeUtil
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Page
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import java.util.*

/**
 * Created on 2021/3/14 18:28
 * @author shuguo
 * 公司
 */
@Api(value = "/Company", tags = arrayOf("公司接口"))
@RestController
@RequestMapping("/company")
class CompanyCtl {

    @Autowired
    lateinit var service:CompanyServiceImpl

    @ApiOperation(value = "添加公司")
    @PostMapping(value = ["/add"])
    fun add(@RequestBody bean:BCompanyEntity) : MyResponse<BCompanyEntity> {
        bean.companyId = ""+SnowflakeUtil.instance.nextId(0)
        return MyResponse(200, "添加成功", service.add(bean))
    }

    @ApiOperation(value = "修改公司")
    @PostMapping(value = ["/update"])
    fun update(@RequestBody @Validated bean:BCompanyEntity) : MyResponse<BCompanyEntity> {
        service.update(bean)
        return MyResponse(200, "修改成功", detail(bean).data)
    }

    @ApiOperation(value = "公司列表")
    @PostMapping(value = ["/list"])
    fun list(@RequestBody @Validated bean: BaseListBean) : MyResponse<Page<BCompanyEntity>> {
        return MyResponse(200, "请求列表成功", service.list(bean.page, bean.size))
    }

    @ApiOperation(value = "删除公司")
    @PostMapping(value = ["/del"])
    fun del(@RequestBody @Validated bean:BCompanyEntity) : MyResponse<Unit> {
        return MyResponse(200, "删除成功", service.del(bean.companyId))
    }

    @ApiOperation(value = "查询公司")
    @PostMapping(value = ["/detail"])
    fun detail(@RequestBody @Validated bean:BCompanyEntity) : MyResponse<BCompanyEntity> {
        return MyResponse(200, "查找成功", service.detail(bean.companyId))
    }
}